package com.laiketui.admin.store.controller.material;

import com.laiketui.common.api.banner.BannerService;
import com.laiketui.common.api.material.MaterialService;
import com.laiketui.core.domain.Result;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.domain.vo.banner.BannerVo;
import com.laiketui.domain.vo.material.MaterialVo;
import com.laiketui.root.annotation.HttpApiMethod;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 材质管理
 *
 */
@Api(tags = "后台-商城材质管理")
@RestController
@RequestMapping("/admin/material/material")
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    @ApiOperation("查询材质数据")
    @RequestMapping("/selectInfo")
    @HttpApiMethod(apiKey = "admin.material.selectInfo")
    public Result selectInfo(MaterialVo vo){
        return Result.success(materialService.selectInfo(vo));
    }

    @ApiOperation("查询材质数据列表")
    @RequestMapping("/selectList")
    @HttpApiMethod(apiKey = "admin.material.selectList")
    public Result selectList(MainVo vo){
        return Result.success(materialService.selectList(vo));
    }

    @ApiOperation("新增材质数据")
    @RequestMapping("/insertMaterial")
    @HttpApiMethod(apiKey = "admin.material.insertMaterial")
    public Result insertMaterial(@Validated MaterialVo vo){
        try {
            materialService.insertMaterial(vo);
            return Result.success();
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("修改材质数据")
    @RequestMapping("/updateMaterial")
    @HttpApiMethod(apiKey = "admin.material.updateMaterial")
    public Result updateMaterial(@Validated MaterialVo vo){
        try {
            materialService.updateMaterial(vo);
            return Result.success();
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("删除材质数据")
    @RequestMapping("/deleteMaterial")
    @HttpApiMethod(apiKey = "admin.material.deleteMaterial")
    public Result deleteMaterial(MaterialVo vo){
        return Result.success(materialService.deleteMaterial(vo));
    }

    @ApiOperation("材质数据上下架")
    @RequestMapping("/updateStatus")
    @HttpApiMethod(apiKey = "admin.material.updateStatus")
    public Result updateStatus(MaterialVo vo){
        return Result.success(materialService.updateStatus(vo));
    }

    @ApiOperation("材质列表下拉")
    @RequestMapping("/skuMaterialList")
    @HttpApiMethod(apiKey = "admin.material.skuMaterialList")
    public Result skuMaterialList(MaterialVo vo){
        return Result.success(materialService.getSkuMaterialList(vo));
    }

}
